package com.hzw.net.page.title

import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.core.view.isVisible
import androidx.lifecycle.LifecycleOwner
import com.hzw.net.databinding.TitleLayoutBinding
import com.hzw.net.delegate.viewBinding
import com.hzw.net.page.layout.AbsTitleLayout

class TitleLayout(
    context: Context,
    owner: LifecycleOwner,
    private val title: String,
    private val isShowLine: Boolean = true
) : AbsTitleLayout(
    context,
    owner
) {

    private val viewBinding: TitleLayoutBinding by viewBinding {
        TitleLayoutBinding.inflate(LayoutInflater.from(context))
    }

    override val rootView: View
        get() = viewBinding.root


    override fun initUI() {
        viewBinding.apply {
            titleBackView.setOnClickListener {
                (context as Activity).onBackPressed()
            }
            titleNameView.text = title
            titleLineView.isVisible = isShowLine
        }
    }

    fun setTitle(title: String) {
        viewBinding.titleNameView.text = title
    }
}